//把里面所有的全局变量全部删掉
function animate(element, target, num) {
    clearInterval(element.timer);
    element.timer = setInterval(function() {
        var leader = element.offsetLeft;
        var step = target > leader ? num : -num;
        if (Math.abs(target - leader) >= Math.abs(step)) {
            leader += step;
            element.style.left = leader + "px";
        } else {
            clearInterval(element.timer);

            element.style.left = target + "px";
        }
    }, 15);
}

$(function() {
    $('.icon_03').addClass('active');
    $('.icon_03 img.white').hide();
    $('.icon_03 img.red').show();

    $('.top .right ul li').mouseenter(function(event) {
        var index = $(this).attr('data-id');
        if (index !== '') {
            // exclusiveList(parseInt(index));
        }
        $('.top .right ul li').removeClass('active');
        $('.top .right ul li img.red').hide();
        $('.top .right ul li img.white').show();
        $('.icon_' + index).addClass('active');
        $('.icon_' + index + ' img.red').show();
        $('.icon_' + index + ' img.white').hide();

    });
});
var istrues = true,
    t = new Date().getTime();
var csrfToken = "YVdmamFMWDQQPi8bMTgoWi4yPAsGFDRbBS4OGywZLHssb15fVBktAA==";

function exclusiveList(id) {
    if (istrues) {
        istrues = false;
        $.ajax({
            type: "GET",
            url: "http://www.86sb.com/adv/sbadvad",
            dataType: 'jsonp',
            jsonp: 'callback',
            data: {
                id: 'all',
                lid: 49,
                page: 1,
                bigclassid: id,
                name: '',
                page_size: 9,
                _csrf: csrfToken,
                t: Math.random()
            },
            success: function(data) {
                var html = '';
                var arr = data.result.data;
                //var classArr = data.result.sbClass;
                if (arr.length > 0) {
                    for (var i = 0; i < arr.length; i++) {
                        html += '<li class="list_time">\
                            <a  class="list_img" href="/info-' + arr[i]['id'] + '.html" target="_blank" title="尚标商标-' + arr[i]['sbname'] + '" onclick="my_hmt_push([\'_trackEvent\', \'pc_index_exclusive\', \'pc_index_exclusive_' + arr[i]['id'] + '\', \'click\']);" >\
                            <img src="' + arr[i]['sbpic'] + '@!hyjs"  alt="尚标-' + arr[i]['sbname'] + '"  >\
                            <p>\
                            <span>' + arr[i]['sbname'].substr(0, 6) + '</span>\
                            <span>' + arr[i]['sbbigclassid_name'] + '</span>\
                            </p>\
                            <p class="use_range" title="' + $.trim(arr[i]['sbbetween']) + '">' + $.trim(arr[i]['sbbetween']) + '</p>\
                            </a>\
                            <a href="javascript:;" class="btn" onclick="toswt(\'\');">立即购买</a>\
                            </li>';
                    }
                } else {
                    html += '<li style="margin-left: 250px; margin-top: 50px;"><a href="javascript:void(0);" onClick="toswt(\'\');" ><img src="/img/nodata1.png"></a></li>';
                }
                html += '';
                $('.imgUl1').html(html);
                var node = $(".imgs ul li")[0].cloneNode(true);
                var node1 = $(".imgs ul li")[1].cloneNode(true);
                var node2 = $(".imgs ul li")[2].cloneNode(true);
                var nodeLast = $(".imgs ul li")[$(".imgs ul li").length - 1].cloneNode(true);

                $(".imgs ul").append(node);
                $(".imgs ul").append(node1);
                $(".imgs ul").append(node2);
                $(".imgs ul").prepend(nodeLast);
                istrues = true;
            }
        });
        //}, "json");

    }

}



$(function() {


    (function() {
        window.onload = function() {

            imgUl1.style.left = -imgWidth1 + "px";
        };

        //下面轮播
        var slide1 = document.getElementsByClassName("bx_box")[0];
        var imgUl1 = document.getElementsByClassName("imgUl1")[0];
        var imgLis1 = imgUl1.children;
        var arrLeft1 = document.getElementsByClassName("btn_left")[0];
        var arrRight1 = document.getElementsByClassName("btn_right")[0];
        var imgWidth1 = imgLis1[0].offsetWidth + 12;

        imgUl1.insertBefore(imgLis1[imgLis1.length - 1].cloneNode(true), imgLis1[0]);
        imgUl1.appendChild(imgLis1[1].cloneNode(true));
        imgUl1.appendChild(imgLis1[2].cloneNode(true));
        imgUl1.appendChild(imgLis1[3].cloneNode(true));
        var count1 = 0;
        var flag1 = true;
        //2. 左右焦点功能
        arrRight1.onclick = function() {
            if (flag1) {
                flag1 = false;
                setTimeout(function() {
                    flag1 = true;
                    if (count1 <= 1) {
                        flag1 = true;
                        count1 = imgLis1.length - 3;
                        imgUl1.style.left = -count1 * imgWidth1 + "px";
                    }
                    count1--;
                    var target1 = -count1 * imgWidth1;
                    animate(imgUl1, target1, 10);
                }, 500)
            }
        };

        arrLeft1.onclick = function() {
            if (flag1) {
                flag1 = false;
                setTimeout(function() {
                    flag1 = true;
                    if (count1 >= imgLis1.length - 3) {
                        count1 = 1;
                        imgUl1.style.left = -count1 * imgWidth1 + "px";
                    }
                    count1++;
                    var target1 = -count1 * imgWidth1;
                    animate(imgUl1, target1, 10);
                }, 500)
            }
        };
        // clearInterval(timer1);
        // 自动轮播功能
        //     var timer1 = setInterval(function () {
        //         arrLeft1.onclick();
        //     }, 3000);


        // slide1.onmouseover = function () {
        //     clearInterval(timer1);
        // }

        // slide1.onmouseout = function () {
        //     clearInterval(timer1);
        //     timer1 = setInterval(function () {
        //         arrLeft1.onclick();
        //     }, 3000);
        // }

    })();
})